<%--
 *  File:    RegionCode.jsp
 *  @Author: Morgan Li
 *  Date:    5/7/2002
 *
 *  Copyright (C) 2000 - 2002 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  // setting logger
  Category cat = Category.getInstance("jsp.RegionCode");
  // variant and initialization
  String strModuleName = "IMG";
  String strTableName = "jpovregionmulti";
  String privilegeCode = "Z0807";

  //get current userinfo
  HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  cat.debug("The userinfo is :"+CurUserInfo);
  cat.info("enter my page");
%>

<%--  include files list --%>

<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<%int LangNums = ConstantProp.multiLangNumber;%>

<html>
<head>
<title>RegionCode</title>
<PageFlow:CheckPageFlow pageName="regioncode"/>
<%@ include file="/inc/SumDiv.inc" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<script language="JavaScript" src="../js/SummaryDivision.js"></script>
<script language="JavaScript" >

  function page_summary(actionvalue,orderbyname)
  {
    var editform = summaryPrepare(document.regioncodeform, actionvalue, orderbyname);
    if (editform == false)
      return;
    editform.action = "RegionCode.jsp?<%= OvalTools.randomURL() %>";
    editform.target = "_self";
    isRunning = true;
    editform.submit();
  }

  function page_contrychange()
  {
    page_summary("search");
  }

  function page_add()
  {
    if (!checkForm(regioncodeform)) return;
    var countrycode = eval("regioncodeform.countrycode");
    syncChange(countrycode, "countrycode", 0, <%=LangNums%>);
    regioncodeform.actionname.value = "add";
    regioncodeform.target = "_self";
    isRunning = true;
    regioncodeform.submit();
  }

  function page_save()
  {
    regioncodeform.actionname.value = "save";
    regioncodeform.target = "_self";
    isRunning = true;
    regioncodeform.submit();
  }

  function page_delete()
  {
    if(isNullChecked(regioncodeform.regioncodes))
    {
      alert('<%=message.getMessageDesc("PLEASE_SELECT")%>');
      return;
    }
    regioncodeform.actionname.value = "delete";
    regioncodeform.target = "_self";
    isRunning = true;
    regioncodeform.submit();
  }

  function page_mulilang(columnname,label,num,need,entitycode)
  {
    if(popwindow!=null)
      popwindow.close();
    var strurl="../common/Lang.jsp?<%= OvalTools.randomURL() %>&form=regioncodeform&module=IMG&mlctype="+label+"&nativelanguage="+need+"&schema=v_regionforjp&qlname=selectbycode&entitycode="+entitycode+"&entitytype="+columnname+"&contentid=regionid&colindex="+num;
    var strStatus= "height=250, width=250,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
    popwindow=window.open(strurl, "newwindow",strStatus);
  }

  function attr1newChange()
  {
    var source = eval("regioncodeform.attr1new");
    syncChange(source, 'attr1', 0, <%=LangNums%>);
  }
  function attr2newChange()
  {
    var source = eval("regioncodeform.attr2new");
    syncChange(source, 'attr2', 0, <%=LangNums%>);
  }

  function codeChange(srcindex, colindex)
  {
    var source = eval("regioncodeform.regioncodebox" + srcindex);
    syncChange(source, "regioncode", colindex, <%=LangNums%>);
  }

  function nameChange()
  {
    var source;
    for (var i = 0; i < <%=LangNums%>; i++)
    {
      var temp = eval("regioncodeform.regionname" + i);
      if (temp.value)
      {
        source = temp;
        break;
      }
    }
    for (var i = 0; i < <%=LangNums%>; i++)
    {
      var dest = eval("regioncodeform.regionname" + i);
      if (dest.value) continue;
      dest.value = source.value;
    }
  }

  function syncChange(source, varname, startindex, syncnum)
  {
    for (var i = 0; i < syncnum; i++)
    {
      var dest = eval("regioncodeform." + varname + (startindex + i));
      dest.value = source.value;
    }
  }

  function newCodeChange()
  {
    var source = eval("regioncodeform.regioncodenew");
    source.value = Trim(source.value);
    if (!dealDuplication(source)) return;
    syncChange(source, "regioncode", 0, <%=LangNums%>);
  }

  function dealDuplication(source)
  {
    if (!checkCodeDuplication(source.value))
    {
      alert('<%=message.getMessageDesc("REGIONCODE_HAS_EXIST")%>');
      source.value = "";
      return false;
    }
    return true;
  }

	function checkCodeDuplication(value)
	{
		var langnum = <%=LangNums%>;
	  for (var i = 1; i <= regioncodeform.nums.value; i++)
	  {
	    var target = eval("regioncodeform.regioncode" + (i * langnum));
	    if (value == target.value)
	    {
	      return false;
	    }
	  }
	  return true;
	}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="regioncodeform" method="post" action="../Dispatcher">
  <input type="hidden" name="pagename" value="regioncode">
  <input type="hidden" name="actionname">
  <input type="hidden" name="nullstring">

<%@ include file="/inc/PageLocation.inc" %>
<%
    Vector allcountrys=(Vector)pageContext.getAttribute("allcountrys");
    if(allcountrys==null)
    {
        allcountrys=new Vector();
    }
    Vector regionsummary=(Vector)pageContext.getAttribute("regionsummary");
    if(regionsummary==null)
    {
        regionsummary=new Vector();
    }

    cat.debug("regionsummary is:"+regionsummary);
    cat.debug("allcountrys is"+allcountrys);

    String strCountryCode=(String)pageContext.getAttribute("countrycode");

    if(strCountryCode==null)
    {
        strCountryCode="";

    }
    //System.out.println("strCountryCode = " + strCountryCode);

    cat.debug("strCountryCode is :"+strCountryCode);
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="summary_top"></td>
  </tr>
  <tr>
    <td width="220">
      <table width="100%">
        <tr>
          <td><%= label.getLabelName("L_Country") + label.getLabelName("L_Colon") %>
            <select name="countrycode" onchange="javascript:page_contrychange();">
              <option value="">------</option>
          <logic:iterate id="allcountrysitem" collection="<%= allcountrys %>">
            <%
                String strSelected="";
                HashMap hmTemp=(HashMap)pageContext.getAttribute("allcountrysitem");
                if(hmTemp==null)
                {
                     hmTemp=new HashMap();
                }
                String oCountryCodeValue=(String)hmTemp.get("countrycode");
                if(oCountryCodeValue==null)
                {
                     oCountryCodeValue="";
                 }

                if(oCountryCodeValue.equalsIgnoreCase(strCountryCode))
                    strSelected="selected";
            %>
              <option value='<custom:write name="allcountrysitem" property="countrycode"/>' <%=JspHelper.filterNull(strSelected)%>><custom:write name="allcountrysitem" property="countryname"/></option>
            </logic:iterate>
            </select>
          </td>
        </tr>
      </table>
    </td>
    <td>
      <table>
        <%@ include file="/inc/SummarySearch.inc" %>
      </table>
      </td>
  </tr>

</table>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td>
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
        <tr class="deepblue-left" >
          <td width="22" class="title_center" >&nbsp;</td>
          <td width="25%" class="title_center"><%= label.getLabelName("L_AreaCode") %></td>
          <td class="title_center" width="25%"><%= label.getLabelName("L_Name") %> </td>
          <td class="title_center"            ><%= label.getLabelName("L_Attr1") %></td>
          <td class="title_center"            ><%= label.getLabelName("L_Attr2") %></td>
        </tr>
        <%
            int i=1;
            String strClassType="";
        %>


        <logic:iterate id="regionsummaryitem" collection="<%= regionsummary %>">
        <%
            Integer oColIndexLang=new Integer(i);
            HashMap hmTemp=(HashMap)pageContext.getAttribute("regionsummaryitem");
            if(hmTemp==null)
            {
                hmTemp=new HashMap();
            }
            String oCountryTemp=(String)hmTemp.get("countrycode");
            if(oCountryTemp==null)
            {
                oCountryTemp="";
            }

            if(oCountryTemp.equalsIgnoreCase(strCountryCode))
            {
                if(i%2 == 0)
                {
                  strClassType = "td-listrom";
                }else{
                  strClassType = "none";
                }
                i++;
        %>

       <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
         <td>
           <input type="checkbox" name="regioncodes" id="regioncodes<%=JspHelper.filterNull(i-1)%>" value="<custom:write name="regionsummaryitem" property="regioncode" />" class="normalradio" />
         </td>
         <td>
         	 <custom:write name="regionsummaryitem" property="regioncode" nbsp="true" />
         </td>
         <td>
           <custom:text name="regionsummaryitem" property="regionname" command="notnull" module="IMG" label="L_Name" colIndex="<%=oColIndexLang%>" isFirstMLC="true" multiLangType="regionname" entityId="regioncode" contentId="regionid" needMLC="true" />
           <a onclick="page_mulilang('regionname','L_Name','<%=oColIndexLang%>','need','<custom:write name="regionsummaryitem" property="regioncode" />');"><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a>
         </td>

         <td>
           <custom:write name="regionsummaryitem" property="attr1" nbsp="true" />
         </td>
         <td>
           <custom:write name="regionsummaryitem" property="attr2" nbsp="true" />
         </td>

       </tr>
        <%}%>
        </logic:iterate>
       <input type=hidden name="nums" value="<%=JspHelper.filterNull(regionsummary.size())%>" />
       <input type=hidden name="numrows" value="<%=LangNums*(JspHelper.filterNull(regionsummary.size() + 1))%>" />
        <%
           if(i%2 == 0)
            {
              strClassType = "td-listrom";
            }else{
              strClassType = "none";
            }
          %>
       <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
         <td width="5%">&nbsp; </td>
         <td>
           <input type="text" name="regioncodenew" command="notnull" label="<%=label.getLabelName("L_AreaCode",false)%>" module="IMG" size="5" onblur="newCodeChange();" />
           <span class="red"> *</span>
         </td>
          <td>
             <custom:text property="regionnamenew" command="notnull" module="IMG" label="L_Name" isFirstMLC="true" multiLangType="regionname" entityId="regioncode" contentId="regionid" needMLC="true" onchange="javascript:nameChange();" />
             <a onclick="page_mulilang('regionname','L_AreaCode','0','need','-1','-1' );"><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a>
         <td>
         	 <custom:text property="attr1new" size="15" onchange="javascript:attr1newChange();" />
           <custom:hidden property="attr1" module="IMG" label="L_Attr1" isFirstMLC="false" multiLangType="attr1" entityId="regioncode" contentId="regionid" needMLC="true" />
         </td>
         <td>
         	 <custom:text property="attr2new" size="15" onchange="javascript:attr2newChange();" />
           <custom:hidden property="attr2" module="IMG" label="L_Attr2" isFirstMLC="false" multiLangType="attr2" entityId="regioncode" contentId="regionid" needMLC="true" />
           <custom:hidden property="countrycode" value="<%=strCountryCode%>" module="IMG" isFirstMLC="false" multiLangType="countrycode" entityId="regioncode" contentId="regionid" needMLC="true" />
         </td>
        </tr>
         <tr>
          <td colspan="6">
            <%@ include file="/inc/SummaryAction.inc" %>
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
      	<tr>
          <td class="summary_top" ></td>
        </tr>
        <tr>
          <td class="td_center">
          <%if(!"".equals(strCountryCode)&&!"-1".equals(strCountryCode)){%>
          <a onclick="page_add();"><custom:button type="1" label="L_Add" imgsrc="add.gif" border="0" style="width:60"/></a>
          <%}%>
          <%
          if(regionsummary.size()>0&&(!"".equals(strCountryCode)&&!"-1".equals(strCountryCode)))
          {
          %>
          <a onclick="page_save();"><custom:button type="1" label="L_Save" imgsrc="save.gif" border="0" style="width:60"/></a>
          <a onclick="page_delete();"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a>
          <%}%>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
</html>
